//
//  connectCreateWifiView.m
//  SKaURobot
//
//  Created by cdong on 16/2/25.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "connectCreateWifiView.h"
#import "FLAnimatedImage.h"

@implementation connectCreateWifiView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

- (void)loadNagavitionViewWithString:(NSString *)nameString{
    self.navigationV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*matchW, 64)];
    self.navigationV.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_bg"]];
    [self addSubview:self.navigationV];
    
    self.navigationVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.frame.size.width - 100)/2), 20, 100, 44)];
    self.navigationVL.text = nameString;
    self.navigationVL.textAlignment = NSTextAlignmentCenter;
    self.navigationVL.textColor = [RGBColorEncapsulation colorWithRGB:0xf8f8f8 alpha:1];
    self.navigationVL.font = [UIFont systemFontOfSize:19];
    [self.navigationV addSubview:self.navigationVL];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.backBtn.frame = CGRectMake(12*matchW, CGRectGetMinY(self.navigationVL.frame) + 7, 30, 30);
    [self.backBtn setBackgroundImage:[UIImage imageNamed:@"2left"] forState:UIControlStateNormal];
    [self.navigationV addSubview:self.backBtn];
}

- (void)setUp{
    [self setBackgroundColor:[RGBColorEncapsulation colorWithRGB:0xf4f4f4 alpha:1]];
    [self loadNagavitionViewWithString:@"连接机器人"];
    
    self.bg_View = [[UIView alloc]initWithFrame:CGRectMake((self.frame.size.width - 340*matchW)/2,17*matchH + 64, 340*matchW,340*matchW)];
    self.bg_View.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:1];
    [self.bg_View.layer setMasksToBounds:YES];
    [self.bg_View.layer setBorderWidth:1];
    [self.bg_View.layer setCornerRadius:5];
    [self.bg_View.layer setBorderColor:[RGBColorEncapsulation colorWithRGB:0xe1e1e1 alpha:1].CGColor];
    [self.bg_View.layer setShadowColor:[RGBColorEncapsulation colorWithRGB:0x000000 alpha:0.3].CGColor];
    [self.bg_View.layer setShadowOffset:CGSizeMake(1, 1)];
    [self addSubview:self.bg_View];
    
    self.iconImageV = [[UIImageView alloc]initWithFrame:CGRectMake(10*matchW, 10*matchH, 40*matchW, 40*matchW)];
    [self.iconImageV.layer setMasksToBounds:YES];
    [self.iconImageV.layer setCornerRadius:20*matchW];
    [self.iconImageV.layer setBorderWidth:1];
    [self.iconImageV.layer setBorderColor:[RGBColorEncapsulation colorWithRGB:0xcecece alpha:1].CGColor];
//    self.iconImageV.image = [UIImage imageNamed:@"wifi"];
    [self.bg_View addSubview:self.iconImageV];
    
    self.userNameL = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.iconImageV.frame) + 20*matchW, 24*matchH, self.frame.size.width - 50*matchW - 20*matchW, 24*matchH)];
//    self.userNameL.text = @"雪儿妈妈";
    self.userNameL.textColor = [RGBColorEncapsulation colorWithRGB:0x333333
                                                              alpha:1];
    self.userNameL.font = [UIFont systemFontOfSize:15];
    [self.bg_View addSubview:self.userNameL];
    
    self.QRCodeImageV = [[UIImageView alloc]initWithFrame:CGRectMake((self.bg_View.frame.size.width - 263*matchW)/2, CGRectGetMaxY(self.iconImageV.frame) + 15*matchH, 263*matchW, 263*matchW)];
    self.QRCodeImageV.backgroundColor = [UIColor yellowColor];
    [self.bg_View addSubview:self.QRCodeImageV];
    
    self.QRExplainL = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.bg_View.frame) + 10*matchH, self.frame.size.width, 12)];
    self.QRExplainL.text = @"用机器人扫一扫上面的二维码图案，连接机器人";
    self.QRExplainL.textAlignment = NSTextAlignmentCenter;
    self.QRExplainL.textColor = [RGBColorEncapsulation colorWithRGB:0x999999 alpha:1];
    self.QRExplainL.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.QRExplainL];
   
    if (self.frame.size.width *2 == 750) {
        self.QEImage = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scanCode@2x.gif" ofType:nil]]];
    }else if (self.frame.size.width *2 == 1080){
        self.QEImage = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scanCode@3x.gif" ofType:nil]]];
    }else if (self.frame.size.width * 2 == 640){
        self.QEImage = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scanCode@1x.gif" ofType:nil]]];
    }else if (self.frame.size.width * 2 == 640){
        self.QEImage = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scanCode@1242x.gif" ofType:nil]]];
    }else{
        self.QEImage = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"scanCode@2x.gif" ofType:nil]]];
    }
     FLAnimatedImageView *QBimageView =
    [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.QRExplainL.frame) + 10*matchH, self.frame.size.width, 214*matchH)];
    QBimageView.backgroundColor = [UIColor redColor];
    QBimageView.animatedImage = self.QEImage;
    [self addSubview:QBimageView];
}

@end
